package md.sv.dbu.config;

import org.w3c.dom.Node;
import org.xml.sax.SAXException;

import javax.xml.bind.JAXBException;
import java.io.InputStream;

/**
 * @author MG
 */
public interface XmlParser {

    boolean hasChildNode(Node node, String nodeName);

    public static interface XmlParserCallback {
        public void setXmlValue(String nodeFullName, String value);
    }

    /**
     * Unmarshal an XML input stream to an object, using an optional validation XSD
     *
     * @param inputStream       The XML InputStream
     * @param clazz             The Class of the unmarshalled object
     * @param validationXsd     The optional XSD file input stream, or {@code null} if no validation required
     * @return The unmarshalled object
     * @throws org.xml.sax.SAXException     When an XML parse exception occurs
     * @throws javax.xml.bind.JAXBException When a JAXB unmarshalling exception occurs
     */
    public <T> T parseConfigFile(InputStream inputStream, Class<T> clazz, InputStream validationXsd) throws JAXBException, SAXException;

    public void parseXmlDocument(Node parentNode, XmlParserCallback callback);

    public Node findNodeByValue(Node node, String value);

    public boolean validateXml(String document, String xsd);

    public boolean validateXml(String documents, String[] xsd);
}
